﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BodyColor : MonoBehaviour
{
    private Color currBodyColor = new Color(1, 1, 1);
    private bool showOutline = false;
    private Material outlineMaterial;
    public bool wantShow = false;
    public Color outlineColor = new Color(0, 0, 0);
    // Start is called before the first frame update
    void Awake()
    {
        outlineMaterial = new Material(Shader.Find("Custom/OutlineShader"));
        outlineMaterial = gameObject.GetComponent<Renderer>().material = outlineMaterial;
        SetOutlineColor();
    }

    // Update is called once per frame
    void Update()
    {
        if (wantShow)
        {
            if (!showOutline)
            {
                outlineMaterial.SetInt("_DualGrid", 1);
                outlineMaterial.EnableKeyword("_ShowOutline");

                showOutline = true;
            }
            wantShow = false;
        }
        else
        {
            if (showOutline)
            {
                outlineMaterial.SetInt("_DualGrid", 0);
                outlineMaterial.DisableKeyword("_ShowOutline");
                showOutline = false;
            }
        }
    }

    public void AddColor(Color color)
    {
        currBodyColor *= color;
        //Debug.Log(currBodyColor);
        outlineMaterial.SetColor("_BodyColor", currBodyColor);
    }

    public void ReplaceColor(Color color)
    {
        currBodyColor = color;
        //Debug.Log(outlineMaterial);
        outlineMaterial.SetColor("_BodyColor", currBodyColor);
    }


    public void SetOutlineColor()
    {
        outlineMaterial.SetColor("_EdgeColor", outlineColor);
    }
}
